import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class MyJFrame2 extends JFrame implements MouseListener {
        JButton jtb1=new JButton("鼠标监听");
    public MyJFrame2(){
        //设置界面宽高
        this.setSize(603, 680);
        //设置界面标题
        this.setTitle("事件演示");
        //设置界面置顶
        this.setAlwaysOnTop(true);
        //设置界面居中
        this.setLocationRelativeTo(null);
        //设置关闭模式
        this.setDefaultCloseOperation(3);
        //取消默认居中,只有取消才会按xy轴放置
        this.setLayout(null);
        //设置位置和宽高
        jtb1.setBounds(0, 0, 100, 50);
        //给整个窗体添加键盘监听
        jtb1.addMouseListener(this);
        //把按钮添加到界面
        this.getContentPane().add(jtb1);
        //展示界面
        this.setVisible(true);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("单机");
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("按下不松");
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("松开");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println("划入");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        System.out.println("划出");
    }
}
